open(BUFF,"combined_GBM_normal_plink.tped");
open(WRBUFF,">combined_GBM_normal_plink_final.tped");
$line = <BUFF>;
chomp($line);
$line =~ s/^\s+//;
@array = split(" ",$line);
$k =0;
for($i=0;$i<@array;$i++)
{
	if(!(exists($hash{$array[$i]})))
	{
		$hash{$array[$i]}  = 1;
		$arr[$i] = $k;
		$jj[$k] = $array[$i];
		$k++;
	}
	else
	{
		$arr[$i] = -1;
	}
}
#print "k$k\n";
$line = join(" ",@jj);
        #print $line."\n";
print WRBUFF $line."\n";
while($line=<BUFF>)
{
	chomp($line);
	@array = split(" ",$line);
	$g1[0] = shift(@array);
	$g1[1] = shift(@array);
	$g1[2] = shift(@array);
	$g1[3] = shift(@array);
	$g1[4] = shift(@array);
        $g1[5] = shift(@array);
        $g1[6] = shift(@array);
	#print $array1[0]."\n";
	for($i=0;$i<@array;$i++)
	{
		if($arr[$i] != -1)
		{
			$array1[$arr[$i]] = $array[$i];
		}
	}
	$line = join(" ",@array1);
	$g1 = join(" ",@g1);
	#print $g1."\n";
	print WRBUFF $g1." ".$line."\n";
}
